# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libtool' 'libltdl')
pkgver=2.4.6
_gccver=9.1.0
pkgrel=8
pkgdesc="A generic library support script"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/libtool/"
license=('GPL')
makedepends=("gcc=${_gccver}")
source=(https://ftp.gnu.org/pub/gnu/libtool/${pkgname}-${pkgver}.tar.xz{,.sig}
        #https://alpha.gnu.org/gnu/libtool/${pkgname}-${pkgver}.tar.xz{,.sig}
        #${pkgname}-${pkgver}::git+https://git.savannah.gnu.org/git/libtool.git
        0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
        0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
        0005-Fix-seems-to-be-moved.patch
        0006-Fix-strict-ansi-vs-posix.patch
        0007-fix-cr-for-awk-in-configure.all.patch
        0009-libtool-2.4.2.418-msysize.patch
        0010-libtool-2.4.2-include-process-h.patch
        0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch
        0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch
        0013-Allow-statically-linking-compiler-support-libraries-.patch)
sha256sums=('7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f'
            'SKIP'
            'fe8b80efd34f9385220ebc90aaec945e44de8c343c75719d6ac0d4e472a6eed5'
            '20ca5f2f339fd27579ff10e503515d871713ef2fdecc6fd74234a1ee67554798'
            'dc39fbe066958178f96108f07db62b48b9339efddf2c21f800ff8d67110ca393'
            '6a94ada08b0a0aa36240efd9ccb826e22ab94ef0969270f2edb8be344dc8c62b'
            'd96beecfc5d15f94ce46bbe0e89d6e6fdb973a25ad6be98c30504b58453792c1'
            'c7d7dccd4a0e7b8dfe6afc47cbaf3862b645179137a90afe1a15d2af606fcab8'
            '0f3defa657d353b9f55469f6d514abd96494ce7459ef76bbd63980d8994cafe9'
            'c727b2b017163cfdeca60820d3cff2dac8968c5630745602b150f92b159af313'
            'c95a65e890b1ae6362807abc66809e72cf81aeea5f9f556e38f9752f974bf435'
            '8069e887aeeab7491f15e00547fa66d9b9e86407f5a23f37a6d8c7d165de752e')


prepare() {
  cd ${srcdir}/${pkgbase}-${pkgver}

  patch -p1 -i ${srcdir}/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
  patch -p1 -i ${srcdir}/0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
  patch -p1 -i ${srcdir}/0005-Fix-seems-to-be-moved.patch
  patch -p1 -i ${srcdir}/0006-Fix-strict-ansi-vs-posix.patch
  patch -p1 -i ${srcdir}/0007-fix-cr-for-awk-in-configure.all.patch

  patch -p1 -i ${srcdir}/0009-libtool-2.4.2.418-msysize.patch
  patch -p1 -i ${srcdir}/0010-libtool-2.4.2-include-process-h.patch
  patch -p1 -i ${srcdir}/0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch
  patch -p1 -i ${srcdir}/0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch
  patch -p1 -i ${srcdir}/0013-Allow-statically-linking-compiler-support-libraries-.patch

}

build() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  ./configure --prefix=/usr lt_cv_sys_lib_dlsearch_path_spec="/usr/lib /lib"
  make -j1
}

check() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  make check
}

package_libtool() {
  depends=('sh' "libltdl=${pkgver}" 'tar')
  groups=('base-devel')
  install=libtool.install

  cd ${srcdir}/${pkgbase}-${pkgver}

  make DESTDIR=${pkgdir} install-binSCRIPTS install-man install-info \
                         install-data-local
}

package_libltdl() {
  pkgdesc="A system independent dlopen wrapper for GNU libtool"
  options=('staticlibs')

  cd ${srcdir}/${pkgbase}-${pkgver}
  make DESTDIR=${pkgdir} install-libLTLIBRARIES install-includeHEADERS \
                         install-ltdlincludeHEADERS
}
